package sort;


import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2023-05-02
 * Time: 7:25
 */
public class sortDeom1 {
    public static void main(String[] args) {
        int[] a = {56, 34, 23, 67, 23, 89, 12};
//        shellSort(a);
        //selectSort(a);
        selectSort1(a);
        System.out.println(Arrays.toString(a));
    }

    private static void selectSort1(int[] a) {
        int l = 0;
        int r = a.length - 1;

        while (l < r) {
            int min = l;
            int max = l;
            for (int i = l + 1; i <= r; i++) {
                if (a[i] < a[min]) {
                    min = i;
                }
                if (a[i] > a[max]) {
                    max = i;
                }
            }
            swap(a, l, min);
            if (l == max) {
                max = min;
            }
            swap(a, r, max);
            l++;
            r--;
        }
    }


    private static void swap ( int[] a, int i, int j){
        int tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
    }
}
